package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import util.ResultSetMapper;
import util.jdbcmysql;
import vo.Member;

public class MemberDao {

	private jdbcmysql sql;
	
	private Connection con = null; 
	private Statement stat = null; 
	private ResultSet rs = null; 
	private PreparedStatement pst = null; 	
	
	private String tableName = "member";
	
	public MemberDao()
	{
		con = new jdbcmysql().getConnection();
	}
	
	public void insert(Member member)
	{
//		sql = new jdbcmysql();
//		
//		String queryStr = String.format("INSERT INTO "+tableName+" "+
//				"VALUES (%s,%s);",member.getEmail(),member.getPassword());
//		
//		return sql.insertTable(queryStr);
	}
	
	public Member searchByID(String memberID)
	{	
		List<Member> pojoList = new ArrayList<Member>();
		ResultSetMapper<Member> resultSetMapper = new ResultSetMapper<Member>();
		String sqlStr = "select * from "+tableName+" as m where m.member_ID = '"+memberID+"' ";
	    try 
	    { 
	      stat = con.createStatement(); 
	      rs = stat.executeQuery(sqlStr); 
	      System.out.println("selectSQL:"+sqlStr);	
	      
	      pojoList= resultSetMapper.mapRersultSetToObject(rs, Member.class);
	      
	    } 
	    catch(SQLException e) 
	    { 
	      System.out.println("searchMemberInfoByList DropDB Exception :" + e.toString()); 
	    } 
	    finally 
	    { 
	      Close(); 
	    }	
	    return pojoList.get(0);
	}
	
	
	private void Close() 
	{ 
	  try 
	  { 
	    if(rs!=null) 
	    { 
	      rs.close(); 
	      rs = null; 
	    } 
	    if(stat!=null) 
	    { 
	      stat.close(); 
	      stat = null; 
	    } 
	    if(pst!=null) 
	    { 
	      pst.close(); 
	      pst = null; 
	    } 
	  } 
	 catch(SQLException e) 
	  { 
	    System.out.println("Close Exception :" + e.toString()); 
	  } 
	}	
	
}
